<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'includes/lib_goods.php');
require_once('../includes/lib_main.php');
require_once("zip.class.php");

$goodsid = $_REQUEST['gid'];
$userid = $_REQUEST['uid'];
$orderno = $_REQUEST['oid'];

//$userdata = get_user_info($userid);
$goodsdata = get_goods_info($goodsid);
//var_dump($goodsdata);

if($goodsid=='' || $userid==''){
    echo '参数错误';
    exit;
}

$sql = "select * from  fmmaked  where uid=".$userid." and goods_id=".$goodsid;
$data = $GLOBALS['db']->getAll($sql);
$pc = count($data);
var_dump($data);
$files = array();
foreach($data as $d){
	$files[] = '../'.$d['url'];
}

/*
//为下载文件创建独立目录
$dir = "download/".$userid.$goodsid.(count($data)).time();

if(!mkdir($dir)){
	echo "系统错误，无法创建压缩目录。";
}
//移至目录
foreach($files as $f){
	$file = $f;
	if(is_file($file)){
		copy($file, $dir.'/'.time().'.png');
	}else{
		echo "File ".$file." is not exist.";
	}
	
}
*/
$downname = $orderno.'_'.time().'.zip';
$zipFileName = 'download/'.$downname;

$zip = new PHPZip();

$zip->Zip($files,$zipFileName);

$fp=@fopen($zipFileName ,"r");
//var_dump($fp);exit;
if($fp===false) {
	echo '系统错误，文件'.$zipFileName.'不存在。';
	exit;
}

$filesize = filesize($zipFileName);

header("Content-type: application/octet-stream;charset=gb2312;");
header("Accept-Ranges: bytes");
header("Accept-Length: ".$filesize);
header("Content-Disposition: attachment; filename=" . $downname);

echo fread($fp,$filesize);
fclose($files);

exit;


?>